package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.CategoryDTO;
import cn.tedu.csmall.product.pojo.vo.CategoryListItemVO;
import cn.tedu.csmall.product.service.CategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 程旭东
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping("/add-new")
    public JsonResult addNew(@RequestBody CategoryDTO categoryDTO){
        categoryService.addNew(categoryDTO);
        return JsonResult.ok();
    }

    @GetMapping("/listByParentId")
    public JsonResult listByParentId(Long parentId){
        List<CategoryListItemVO>categoryDTOS = categoryService.listByParentId(parentId);
        return JsonResult.ok(categoryDTOS);
    }

}
